﻿Imports System.Threading
Imports AdvanceWars.Data
Imports System.IO

Public Class frmShow

    Private thrUI As Thread
    Private Sub frmShow_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim p As String = OpenFilePath("*.aws|*.aws")
        If p.Length > 0 Then
            Dim Map As AWSMap = AWSMap.FromFile(p)

            Csv.Save("C:\Documents and Settings\Administrator\桌面\AW\U1.csv", AWSMap.GetTable(Map.u1))
            Csv.Save("C:\Documents and Settings\Administrator\桌面\AW\U2.csv", AWSMap.GetTable(Map.u2))
            Csv.Save("C:\Documents and Settings\Administrator\桌面\AW\T1.csv", AWSMap.GetTable(Map.t1))
            Csv.Save("C:\Documents and Settings\Administrator\桌面\AW\T2.csv", AWSMap.GetTable(Map.t2))
        End If
    End Sub

    Private Sub frmShow_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
        ImageGraphics.Draw(e.Graphics)
    End Sub

    Private Sub tmrPaint_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrPaint.Tick
        ImageGraphics.Draw(PictureBox1)
    End Sub

    Private Shared Function OpenFilePath(Optional ByVal Filter As String = "") As String
        Dim Path As String = String.Empty
        Using op As New OpenFileDialog
            op.InitialDirectory = "F:\AWDS\Map\AWSMapEditor\Samples"
            op.Filter = "All Supported Map Files|*.awd;*.aws|Advance Wars DS v1 Maps (*.awd)|*.awd|Advance Wars Series Maps (*.aws)|*.aws"
            op.Multiselect = False
            If op.ShowDialog = 1 Then
                Path = op.FileName
            End If
        End Using
        Return Path
    End Function

End Class